package cc.bookcloud.tool.ocr.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import cc.bookcloud.tool.ocr.common.parsetext.OcrTextParseAbstract;

/**
 * @Desc: @todo
 * @Version: 2.0
 * @Author: John Goo
 * @Date: 2024/12/03 10:05
 **/
public class OcrTextResponseTransferUtil {

    public static JSONArray transferObjectJson(OcrTextParseAbstract ocrTextParse){
        JSONArray array = new JSONArray();
        JSONObject data = (JSONObject) JSON.toJSON(ocrTextParse);
        // 去掉元数据
        data.remove("elementTemplateList");
        data.remove("metaMap");
        array.add(data);
        return array;
    }

    public static JSONArray transferDictJson(OcrTextParseAbstract ocrTextParse){
        JSONArray array = new JSONArray();
        //JSONObject data = (JSONObject) JSON.toJSON(ocrTextParse);
        // 去掉元数据
        // data.remove("elementTemplateList");
        // data.remove("metaMap");
        JSONObject data = new JSONObject();
        data.put("type",ocrTextParse.getType());
        data.put("typeDesc",ocrTextParse.getTypeDesc());
        data.put("eleList", ocrTextParse.transferJsonArray());
        array.add(data);
        return array;
    }

    /**
     * @Desc：转换成两种混合json格式（测试使用）
    * @Author：John Goo
    * @Date：2024/12/3 10:22
    * @param ocrTextParse
    * @return JSONArray
    */
    public static JSONArray transferMix2Json(OcrTextParseAbstract ocrTextParse){
        JSONArray array = new JSONArray();
        JSONObject data = (JSONObject) JSON.toJSON(ocrTextParse);
        // 去掉元数据
         data.remove("elementTemplateList");
         data.remove("metaMap");
        array.add(data);
        JSONObject data2 = new JSONObject();
        data2.put("type",ocrTextParse.getType());
        data2.put("typeDesc",ocrTextParse.getTypeDesc());
        data2.put("eleList", ocrTextParse.transferJsonArray());
        array.add(data2);

        return array;
    }





}
